<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>位置确认</title>
</head>
<body>
  <h2>点击按钮分享您的位置</h2>
  <button onclick="sendLocation()">分享位置</button>

  <script>
    function sendLocation() {
      if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(pos) {
          fetch("/api/location", {
            method: "POST",
            headers: {"Content-Type": "application/json"},
            body: JSON.stringify({
              latitude: pos.coords.latitude,
              longitude: pos.coords.longitude,
              accuracy: pos.coords.accuracy,
              timestamp: new Date().toISOString()
            })
          }).then(r => alert("位置已提交成功！")).catch(e => alert("提交失败"));
        }, function(err) {
          alert("获取位置失败：" + err.message);
        });
      } else {
        alert("您的浏览器不支持定位");
      }
    }
  </script>
</body>
</html>
